package com.greenx.hello;

/**
 * 
 * @author Stephen Xianwei Zhang
 * 
 */
public class MD5Encrypt {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String hash = "F61D6947467CCD3AA5AF24DB320235DD";
		try {
			String md5 = encrypt(hash);
			System.out.println(md5);
		} catch (Exception e) {
		}
	}

	/**
	 * encrypt str by MD5
	 * 
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String encrypt(String str) throws Exception {
		java.security.MessageDigest d = null;
		d = java.security.MessageDigest.getInstance("MD5");
		d.reset();
		d.update(str.getBytes());
		String result = "";
		byte by[] = d.digest();
		for (int i = 0; i < by.length; i++) {
			result += Integer.toString((by[i] & 0xff), 16);
		}
		return result;
	}
}
